package com.dshore.messagecenter.quartz;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.dshore.messagecenter.quartz.dataStat.ExceptionMsgStat;
import com.dshore.messagecenter.quartz.dataStat.MonitorDateStat;
import com.dshore.messagecenter.quartz.dataStat.RabbitInfoStat;
import com.dshore.messagecenter.service.statistics.MessageService;
import com.dshore.messagecenter.service.warning.WarningRecordService;

@Component
@EnableScheduling
public class Quartz {
	
	@Autowired
	private MessageService messageService;
	@Autowired
	private RabbitInfoStat rabbitInfoStat;
	@Autowired
	private ExceptionMsgStat exceptionMsgStat;
	@Autowired
	private MonitorDateStat monitorDateStat;
//	@Autowired
//	private MsgLogStat msgLogStat;
	@Autowired
	private WarningRecordService warningRecordService;
	
	@Value("${monitor.enable}")
	private String monitorEnable;
	
	
	@Scheduled(cron = "0 */5 * * * *")
	public void memoryAndDisk() {
		if (monitorEnable.equals("on")) {
			messageService.insertCurrentKPI(rabbitInfoStat.getCurrentRabbitMonitor());
		}
	}
	
	@Scheduled(cron = "0 1/5 * * * *")
	public void numAndDelay() {
		if (monitorEnable.equals("on")) {
			List<Object[]> records = monitorDateStat.receiveMonitorData();
			if (records != null && records.size() > 0) {
				messageService.insertCurrentKPI(records);
			}
		}
	}
	
	@Scheduled(cron = "0/10 * * * * *")
	public void exceptionMsgStat() {
		if (monitorEnable.equals("on")) {
			exceptionMsgStat.receiveExceptionMsg();
		}
	}
	
//	@Scheduled(cron = "0/5 * * * * *")
//	public void msgLogStat() {
//		if (monitorEnable.equals("on")) {
//			msgLogStat.receiveMsgLog();
//		}
//	}
	
	@Scheduled(cron = "0 */5 * * * *")
	public void warningFive() {
		if (monitorEnable.equals("on")) {
			warningRecordService.fiveMinuteWarning();
		}
	}
	
	@Scheduled(cron = "0 */10 * * * *")
	public void warningTen() {
		if (monitorEnable.equals("on")) {
			warningRecordService.tenMinuteWarning();
		}
	}
}
